home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / GD.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  27.8 KB  |  1,012 lines

  1. package GD;
  2.  
  3.  
  4. require 5.002;
  5. require Exporter;
  6. require DynaLoader;
  7. require AutoLoader;
  8.  
  9. @ISA = qw(Exporter DynaLoader);
  10. @EXPORT = qw(
  11.     gdBrushed
  12.     gdDashSize
  13.     gdMaxColors
  14.     gdStyled
  15.     gdStyledBrushed
  16.     gdTiled
  17.     gdTransparent
  18.     gdSmallFont
  19.     gdLargeFont
  20.     gdMediumBoldFont
  21.     gdTinyFont
  22. );
  23. sub AUTOLOAD {
  24.  
  25.     my($constname);
  26.     ($constname = $AUTOLOAD) =~ s/.*:://;
  27.     $val = constant($constname, @_ ? $_[0] : 0);
  28.     if ($! != 0) {
  29.     if ($! =~ /Invalid/) {
  30.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  31.         goto &AutoLoader::AUTOLOAD;
  32.     }
  33.     else {
  34.         ($pack,$file,$line) = caller;
  35.         die "Your vendor has not defined GD macro $pack\:\:$constname, used at $file line $line.\n";
  36.     }
  37.     }
  38.     eval "sub $AUTOLOAD { $val }";
  39.     goto &$AUTOLOAD;
  40. }
  41.  
  42. bootstrap GD;
  43.  
  44. sub GD::gdSmallFont {
  45.     return &GD::Font::Small;
  46. }
  47.  
  48. sub GD::gdLargeFont {
  49.     return &GD::Font::Large;
  50. }
  51.  
  52. sub GD::gdMediumBoldFont {
  53.     return &GD::Font::MediumBold;
  54. }
  55.  
  56. sub GD::gdTinyFont {
  57.     return &GD::Font::Tiny;
  58. }
  59.  
  60. sub GD::fileno {
  61.     my($fh) = @_;
  62.     my($package) = caller;
  63.     return fileno "$package\:\:$fh";
  64. }
  65.  
  66. sub GD::Polygon::new {
  67.     my $class = shift;
  68.     return bless { 'length'=>0,'points'=>[] },$class;
  69. }
  70.  
  71. sub GD::Polygon::DESTROY {
  72.     my $self = shift;
  73.     undef $self->{'points'};
  74. }
  75.  
  76. sub GD::Polygon::addPt {
  77.     my($self,$x,$y) = @_;
  78.     push(@{$self->{'points'}},[$x,$y]);
  79.     $self->{'length'}++;
  80. }
  81.  
  82. sub GD::Polygon::getPt {
  83.     my($self,$index) = @_;
  84.     return () unless ($index>=0) && ($index<$self->{'length'});
  85.     return @{$self->{'points'}->[$index]};
  86. }
  87.  
  88. sub GD::Polygon::setPt {
  89.     my($self,$index,$x,$y) = @_;
  90.     unless (($index>=0) && ($index<$self->{'length'})) {
  91.     warn "Attempt to set an undefined polygon vertex";
  92.     return undef;
  93.     }
  94.     @{$self->{'points'}->[$index]} = ($x,$y);
  95.     1;
  96. }
  97.  
  98. sub GD::Polygon::length {
  99.     my $self = shift;
  100.     return $self->{'length'};
  101. }
  102.  
  103. sub GD::Polygon::vertices {
  104.     my $self = shift;
  105.     return @{$self->{'points'}};
  106. }
  107.  
  108. sub GD::Polygon::bounds {
  109.     my $self = shift;
  110.     my($top,$bottom,$left,$right) = @_;
  111.     $top =    99999999;
  112.     $bottom =-99999999;
  113.     $left =   99999999;
  114.     $right = -99999999;
  115.     my $v;
  116.     foreach $v ($self->vertices) {
  117.     $left = $v->[0] if $left > $v->[0];
  118.     $right = $v->[0] if $right < $v->[0];
  119.     $top = $v->[1] if $top > $v->[1];
  120.     $bottom = $v->[1] if $bottom < $v->[1];
  121.     }
  122.     return ($left,$top,$right,$bottom);
  123. }
  124.  
  125. sub GD::Polygon::delete {
  126.     my($self,$index) = @_;
  127.     my($vertex) = splice(@{$self->{'points'}},$index,1);
  128.     return @$vertex;
  129. }
  130.  
  131. sub GD::Polygon::offset {
  132.     my($self,$dh,$dv) = @_;
  133.     my $size = $self->length;
  134.     my($i);
  135.     for ($i=0;$i<$size;$i++) {
  136.     my($x,$y)=$self->getPt($i);
  137.     $self->setPt($i,$x+$dh,$y+$dv);
  138.     }
  139. }
  140.  
  141. sub GD::Polygon::map {
  142.     my($self,$srcL,$srcT,$srcR,$srcB,$destL,$destT,$destR,$destB) = @_;
  143.     my($factorV) = ($destB-$destT)/($srcB-$srcT);
  144.     my($factorH) = ($destR-$destL)/($srcR-$srcL);
  145.     my($vertices) = $self->length;
  146.     my($i);
  147.     for ($i=0;$i<$vertices;$i++) {
  148.     my($x,$y) = $self->getPt($i);
  149.     $x = int($destL + ($x - $srcL) * $factorH);
  150.     $y = int($destT + ($y - $srcT) * $factorV);
  151.     $self->setPt($i,$x,$y);
  152.     }
  153. }
  154.  
  155. 1;
  156. __END__
  157.  
  158. =head1 NAME
  159.  
  160. GD.pm - Interface to Gd Graphics Library
  161.  
  162. =head1 DESCRIPTION
  163.  
  164. B<GD.pm> is a port of Thomas Boutell's gd graphics library (see
  165. below).  GD allows you to create color drawings using a large number of
  166. graphics primitives, and emit the drawings as GIF files.
  167.  
  168. GD defines the following three classes:
  169.  
  170. =over 5
  171.  
  172. =item C<GD::Image>
  173.  
  174. An image class, which holds the image data and accepts graphic
  175. primitive method calls.
  176.  
  177. =item C<GD::Font>
  178.  
  179. A font class, which holds static font information and used for text
  180. rendering.
  181.  
  182. =item C<GD::Polygon>
  183.  
  184. A simple polygon object, used for storing lists of vertices prior to
  185. rendering a polygon into an image.
  186.  
  187. =back
  188.  
  189. A Simple Example:
  190.  
  191.  
  192.     use GD;
  193.     
  194.     $im = new GD::Image(100,100);
  195.  
  196.     $white = $im->colorAllocate(255,255,255);
  197.     $black = $im->colorAllocate(0,0,0);       
  198.     $red = $im->colorAllocate(255,0,0);      
  199.     $blue = $im->colorAllocate(0,0,255);
  200.  
  201.     $im->transparent($white);
  202.     $im->interlaced('true');
  203.  
  204.     $im->rectangle(0,0,99,99,$black);
  205.  
  206.     $im->arc(50,50,95,75,0,360,$blue);
  207.  
  208.     $im->fill(50,50,$red);
  209.  
  210.     print $im->gif;
  211.  
  212. Notes:
  213.  
  214. =over 5
  215.  
  216. =item 1.
  217. To create a new, empty image, send a new() message to GD::Image, passing
  218. it the width and height of the image you want to create.  An image
  219. object will be returned.  Other class methods allow you to initialize
  220. an image from a preexisting GIF, GD or XBM file.
  221.  
  222. =item 2.
  223. Next you will ordinarily add colors to the image's color table.
  224. colors are added using a colorAllocate() method call.  The three
  225. parameters in each call are the red, green and blue (rgb) triples for
  226. the desired color.  The method returns the index of that color in the
  227. image's color table.  You should store these indexes for later use.
  228.  
  229. =item 3.
  230. Now you can do some drawing!  The various graphics primitives are
  231. described below.  In this example, we do some text drawing, create an
  232. oval, and create and draw a polygon.
  233.  
  234. =item 4.
  235. Polygons are created with a new() message to GD::Polygon.  You can add
  236. points to the returned polygon one at a time using the addPt() method.
  237. The polygon can then be passed to an image for rendering.
  238.  
  239. =item 5.
  240. When you're done drawing, you can convert the image into GIF format by
  241. sending it a gif() message.  It will return a (potentially large)
  242. scalar value containing the binary data for the image.  Ordinarily you
  243. will print it out at this point or write it to a file.
  244.  
  245. =back
  246.  
  247. =head1 Method Calls
  248.  
  249.  
  250. =head2 Creating and Saving Images
  251.  
  252. =over 5
  253.  
  254. =item C<new>
  255.  
  256. C<GD::Image::new(width,height)> I<class method>
  257.  
  258. To create a new, blank image, send a new() message to the GD::Image
  259. class.  For example:
  260.  
  261.     $myImage = new GD::Image(100,100) || die;
  262.  
  263. This will create an image that is 100 x 100 pixels wide.  If you don't
  264. specify the dimensions, a default of 64 x 64 will be chosen. If
  265. something goes wrong (e.g. insufficient memory), this call will
  266. return undef.
  267.  
  268. =item C<newFromGif>
  269.  
  270. C<GD::Image::newFromGif(FILEHANDLE)> I<class method>
  271.  
  272. This will create an image from a GIF file read in through the provided
  273. filehandle.  The filehandle must previously have been opened on a
  274. valid GIF file or pipe.  If successful, this call will return an
  275. initialized image which you can then manipulate as you please.  If it
  276. fails, which usually happens if the thing at the other end of the
  277. filehandle is not a valid GIF file, the call returns undef.  Notice
  278. that the call doesn't automatically close the filehandle for you.
  279.  
  280. To get information about the size and color usage of the information,
  281. you can call the image query methods described below.
  282.  
  283.     Example usage:
  284.  
  285.     open (GIF,"barnswallow.gif") || die;
  286.     $myImage = newFromGif GD::Image(GIF) || die;
  287.     close GIF;
  288.  
  289. =item C<newFromXbm>
  290.  
  291. C<GD::Image::newFromXbm(FILEHANDLE)> I<class method>
  292.  
  293. This works in exactly the same way as C<newFromGif>, but reads the
  294. contents of an X Bitmap file:
  295.  
  296.     open (XBM,"coredump.xbm") || die;
  297.     $myImage = newFromXbm GD::Image(XBM) || die;
  298.     close XBM;
  299.  
  300. =item C<newFromGd>
  301.  
  302. C<GD::Image::newFromGd(FILEHANDLE)> I<class method>
  303.  
  304. This works in exactly the same way as C<newFromGif>, but reads the
  305. contents of a GD file.  GD is Tom Boutell's disk-based storage format,
  306. intended for the rare case when you need to read and write the image
  307. to disk quickly.  It's not intended for regular use, because, unlike
  308. GIF or JPEG, no image compression is performed and these files can
  309. become B<BIG>.
  310.  
  311.     open (GDF,"godzilla.gd") || die;
  312.     $myImage = newFromGd GD::Image(GDF) || die;
  313.     close GDF;
  314.  
  315. =item C<gif>
  316.  
  317. C<GD::Image::gif> I<object method>
  318.  
  319. This returns the image data in GIF format.  You can then print it,
  320. pipe it to a display program, or write it to a file.  Example:
  321.  
  322.     $gif_data = $myImage->gif;
  323.     open (DISPLAY,"| display -") || die;
  324.     print DISPLAY $gif_data;
  325.     close DISPLAY;
  326.  
  327. =item C<gd>
  328.  
  329. C<GD::Image::gd> I<object method>
  330.  
  331. This returns the image data in GD format.  You can then print it,
  332. pipe it to a display program, or write it to a file.  Example:
  333.  
  334.     print MYOUTFILE $myImage->gd;
  335.  
  336. =back
  337.  
  338. =head2 Color Control
  339.  
  340. =over 5
  341.  
  342. =item C<colorAllocate>
  343.  
  344. C<GD::Image::colorAllocate(red,green,blue)> I<object method>
  345.  
  346. This allocates a color with the specified red, green and blue
  347. components and returns its index in the color table, if specified.
  348. The first color allocated in this way becomes the image's background
  349. color.  (255,255,255) is white (all pixels on).  (0,0,0) is black (all
  350. pixels off).  (255,0,0) is fully saturated red.  (127,127,127) is 50%
  351. gray.  You can find plenty of examples in /usr/X11/lib/X11/rgb.txt.
  352.  
  353. If no colors are allocated, then this function returns -1.
  354.  
  355. Example:
  356.  
  357.     $white = $myImage->colorAllocate(0,0,0); #background color
  358.     $black = $myImage->colorAllocate(255,255,255);
  359.     $peachpuff = $myImage->colorAllocate(255,218,185);
  360.  
  361. =item C<colorDeallocate>
  362.  
  363. C<GD::Image::colorDeallocate(colorIndex)> I<object method> 
  364.  
  365. This marks the color at the specified index as being ripe for
  366. reallocation.  The next time colorAllocate is used, this entry will be
  367. replaced.  You can call this method several times to deallocate
  368. multiple colors.  There's no function result from this call.
  369.  
  370. Example:
  371.  
  372.     $myImage->colorDeallocate($peachpuff);
  373.     $peachy = $myImage->colorAllocate(255,210,185);
  374.  
  375. =item C<colorClosest>
  376.  
  377. C<GD::Image::colorClosest(red,green,blue)> I<object method>
  378.  
  379. This returns the index of the color closest in the color table to the
  380. red green and blue components specified.  If no colors have yet been
  381. allocated, then this call returns -1.
  382.  
  383. Example:
  384.  
  385.     $apricot = $myImage->colorClosest(255,200,180);
  386.  
  387. =item C<colorExact>
  388.  
  389. C<GD::Image::colorExact(red,green,blue)> I<object method>
  390.  
  391. This returns the index of a color that exactly matches the specified
  392. red green and blue components.  If such a color is not in the color
  393. table, this call returns -1.
  394.  
  395.     $rosey = $myImage->colorExact(255,100,80);
  396.     warn "Everything's coming up roses.\n" if $rosey >= 0;
  397.  
  398. =item C<colorsTotal>
  399.  
  400. C<GD::Image::colorsTotal)> I<object method>
  401.  
  402. This returns the total number of colors allocated in the object.
  403.  
  404.     $maxColors = $myImage->colorsTotal;
  405.  
  406. =item C<getPixel>
  407.  
  408. C<GD::Image::getPixel(x,y)> I<object method>
  409.  
  410. This returns the color table index underneath the specified
  411. point.  It can be combined with rgb()
  412. to obtain the rgb color underneath the pixel.
  413.  
  414. Example:
  415.  
  416.         $index = $myImage->getPixel(20,100);
  417.         ($r,$g,$b) = $myImage->rgb($index);
  418.  
  419. =item C<rgb>
  420.  
  421. C<GD::Image::rgb(colorIndex)> I<object method>
  422.  
  423. This returns a list containing the red, green and blue components of
  424. the specified color index.
  425.  
  426. Example:
  427.  
  428.     @RGB = $myImage->rgb($peachy);
  429.  
  430. =item C<transparent>
  431.  
  432. C<GD::Image::transparent(colorIndex)> I<object method>
  433.  
  434. This marks the color at the specified index as being transparent.
  435. Portions of the image drawn in this color will be invisible.  This is
  436. useful for creating paintbrushes of odd shapes, as well as for
  437. making GIF backgrounds transparent for displaying on the Web.  Only
  438. one color can be transparent at any time. To disable transparency, 
  439. specify -1 for the index.  
  440.  
  441. If you call this method without any parameters, it will return the
  442. current index of the transparent color, or -1 if none.
  443.  
  444. Example:
  445.  
  446.     open(GIF,"test.gif");
  447.     $im = newFromGif GD::Image(GIF);
  448.     $white = $im->colorClosest(255,255,255); # find white
  449.     $im->transparent($white);
  450.     print $im->gif;
  451.  
  452. =back
  453.  
  454. =head2 Special Colors
  455.  
  456. GD implements a number of special colors that can be used to achieve
  457. special effects.  They are constants defined in the GD::
  458. namespace, but automatically exported into your namespace when the GD
  459. module is loaded.
  460.  
  461. =over 5
  462.  
  463. =item C<setBrush>
  464.  
  465. =item C<gdBrushed>
  466.  
  467. C<GD::Image::setBrush( )> and C<GD::gdBrushed>
  468.  
  469. You can draw lines and shapes using a brush pattern.  Brushes are 
  470. just images that you can create and manipulate in the usual way. When
  471. you draw with them, their contents are used for the color and shape of
  472. the lines.
  473.  
  474. To make a brushed line, you must create or load the brush first, then
  475. assign it to the image using C<setBrush>.  You can then draw in that
  476. with that brush using the C<gdBrushed> special color.  It's often 
  477. useful to set the background of the brush to transparent so that 
  478. the non-colored parts don't overwrite other parts of your image.
  479.  
  480. Example:
  481.  
  482.     $diagonal_brush = new GD::Image(5,5);
  483.     $white = $diagonal_brush->allocateColor(255,255,255);
  484.     $black = $diagonal_brush->allocateColor(0,0,0);
  485.     $diagonal_brush->transparent($white);
  486.     $diagonal_brush->line(0,4,4,0,$black); # NE diagonal
  487.  
  488.     $myImage->setBrush($diagonal_brush);
  489.     
  490.     $myImage->arc(50,50,25,25,0,360,gdBrushed);
  491.  
  492. =item C<setStyle>
  493.  
  494. =item C<gdStyled>
  495.  
  496. C<GD::Image::setStyle(@colors)> and C<GD::gdStyled>
  497.  
  498. Styled lines consist of an arbitrary series of repeated colors and are
  499. useful for generating dotted and dashed lines.  To create a styled
  500. line, use C<setStyle> to specify a repeating series of colors.  It
  501. accepts an array consisting of one or more color indexes.  Then
  502. draw using the C<gdStyled> special color.  Another special color,
  503. C<gdTransparent> can be used to introduce holes in the line, as the
  504. example shows.
  505.  
  506. Example:
  507.  
  508.     $myImage->setStyle($yellow,$yellow,$yellow,$yellow,
  509.                $blue,$blue,$blue,$blue,
  510.                gdTransparent,gdTransparent);
  511.     $myImage->arc(50,50,25,25,0,360,gdStyled);
  512.  
  513. To combine the C<gdStyled> and C<gdBrushed> behaviors, you can specify
  514. C<gdStyledBrushed>.  In this case, a pixel from the current brush
  515. pattern is rendered wherever the color specified in setStyle() is
  516. neither gdTransparent nor 0.
  517.  
  518. =item C<gdTiled>
  519.  
  520. Draw filled shapes and flood fills using a pattern.  The pattern is
  521. just another image.  The image will be tiled multiple times in order
  522. to fill the required space, creating wallpaper effects.  You must call
  523. C<setTile> in order to define the particular tile pattern you'll use
  524. for drawing when you specify the gdTiled color.
  525. details.
  526.  
  527. =item C<gdStyled>
  528.  
  529. The gdStyled color is used for creating dashed and dotted lines.  A
  530. styled line can contain any series of colors and is created using the
  531. C<setStyled> command.
  532.  
  533. =back
  534.  
  535. =head2 Drawing Commands
  536.  
  537. =over 5
  538.  
  539. =item C<setPixel>
  540.  
  541. C<GD::Image::setPixel(x,y,color)> I<object method> 
  542.  
  543. This sets the pixel at (x,y) to the specified color index.  No value
  544. is returned from this method.  The coordinate system starts at the
  545. upper left at (0,0) and gets larger as you go down and to the right.
  546. You can use a real color, or one of the special colors gdBrushed, 
  547. gdStyled and gdStyledBrushed can be specified.
  548.  
  549. Example:
  550.  
  551.     $myImage->setPixel(50,50,$peach);
  552.  
  553. =item C<line>
  554.  
  555. C<GD::Image::line(x1,y1,x2,y2,color)> I<object method>
  556.  
  557. This draws a line from (x1,y1) to (x2,y2) of the specified color.  You
  558. can use a real color, or one of the special colors gdBrushed, 
  559. gdStyled and gdStyledBrushed.
  560.  
  561. Example:
  562.  
  563.     $myImage->line(0,0,150,150,gdBrushed);
  564.  
  565. =item C<dashedLine>
  566.  
  567. C<GD::Image::dashedLine(x1,y1,x2,y2,color)> I<object method>
  568.  
  569. This draws a dashed line from (x1,y1) to (x2,y2) in the specified
  570. color.  A more powerful way to generate arbitrary dashed and dotted
  571. lines is to use the setStyle() method described below and to draw with
  572. the special color gdStyled.
  573.  
  574. Example:
  575.  
  576.     $myImage->dashedLine(0,0,150,150,$blue);
  577.  
  578. =item C<rectangle>
  579.  
  580. C<GD::Image::rectangle(x1,y1,x2,y2,color)> I<object method>
  581.  
  582. This draws a rectangle with the specified color.  (x1,y1) and (x2,y2)
  583. are the upper left and lower right corners respectively.  Both real 
  584. color indexes and the special colors gdBrushed, gdStyled and 
  585. gdStyledBrushed are accepted.
  586.  
  587. Example:
  588.  
  589.     $myImage->rectangle(10,10,100,100,$rose);
  590.  
  591. =item C<filledRectangle>
  592.  
  593. C<GD::Image::filledRectangle(x1,y1,x2,y2,color)> I<object method>
  594.  
  595. This draws a rectangle filed with the specified color.  You can use a
  596. real color, or the special fill color gdTiled to fill the polygon
  597. with a pattern.
  598.  
  599. Example:
  600.  
  601.     open(GIF,"happyface.gif") || die;
  602.     $tile = newFromGif GD::Image(GIF);
  603.     $myImage->setTile($tile); 
  604.  
  605.     $myImage->filledRectangle(10,10,150,200,gdTiled);
  606.  
  607. =item C<polygon>
  608.  
  609. C<GD::Image::polygon(polygon,color)> I<object method> 
  610.  
  611. This draws a polygon with the specified color.  The polygon must be
  612. created first (see below).  The polygon must have at least three
  613. vertices.  If the last vertex doesn't close the polygon, the method
  614. will close it for you.  Both real color indexes and the special 
  615. colors gdBrushed, gdStyled and gdStyledBrushed can be specified.
  616.  
  617. Example:
  618.  
  619.     $poly = new GD::Polygon;
  620.     $poly->addPt(50,0);
  621.     $poly->addPt(99,99);
  622.     $poly->addPt(0,99);
  623.     $myImage->polygon($poly,$blue);
  624.  
  625. =item C<filledPolygon>
  626.  
  627. C<GD::Image::filledPolygon(poly,color)> I<object method>
  628.  
  629. This draws a polygon filled with the specified color.  You can use a
  630. real color, or the special fill color gdTiled to fill the polygon
  631. with a pattern.
  632.  
  633. Example:
  634.  
  635.     $poly = new GD::Polygon;
  636.     $poly->addPt(50,0);
  637.     $poly->addPt(99,99);
  638.     $poly->addPt(0,99);
  639.  
  640.     $myImage->filledPolygon($poly,$peachpuff);
  641.  
  642. =item C<arc>
  643.  
  644. C<GD::Image::arc(cx,cy,width,height,start,end,color)> I<object method>
  645.  
  646. This draws arcs and ellipses.  (cx,cy) are the center of the arc, and
  647. (width,height) specify the width and height, respectively.  The
  648. portion of the ellipse covered by the arc are controlled by start and
  649. end, both of which are given in degrees from 0 to 360.  Zero is at the
  650. top of the ellipse, and angles increase clockwise.  To specify a
  651. complete ellipse, use 0 and 360 as the starting and ending angles.  To
  652. draw a circle, use the same value for width and height.
  653.  
  654. You can specify a normal color or one of the special colors gdBrushed,
  655. gdStyled, or gdStyledBrushed.
  656.  
  657. Example:
  658.  
  659.     $myImage->arc(100,100,50,50,0,180,$blue);
  660.  
  661. =item C<fill>
  662.  
  663. C<GD::Image::fill(x,y,color)> I<object method>
  664.  
  665. This method flood-fills regions with the specified color.  The color
  666. will spread through the image, starting at point (x,y), until it is
  667. stopped by a pixel of a different color from the starting pixel (this
  668. is similar to the "paintbucket" in many popular drawing toys).  You
  669. can specify a normal color, or the special color gdTiled, to flood-fill
  670. with patterns.
  671.  
  672. Example:
  673.  
  674.     $myImage->rectangle(10,10,100,100,$black);
  675.     $myImage->fill(50,50,$blue);
  676.  
  677. =item C<GD::Image::fillToBorder(x,y,bordercolor,color)> I<object method>
  678.  
  679. Like C<fill>, this method flood-fills regions with the specified color,
  680. starting at position (x,y).
  681. However, instead of stopping when it hits a pixel of a different color
  682. than the starting pixel, flooding will only stop when it hits the
  683. color specified by bordercolor.  You must specify a normal indexed
  684. color for the bordercolor.  However, you are free to use the gdTiled
  685. color for the fill.
  686.  
  687. Example:
  688.  
  689.     $myImage->rectangle(10,10,100,100,$black);
  690.     $myImage->fillToBorder(50,50,$black,$blue);
  691.  
  692. =back
  693.  
  694. =head2 Image Copying Commands
  695.  
  696. Two methods are provided for copying a rectangular region from one
  697. image to another.  One method copies a region without resizing it.
  698. The other allows you to stretch the region during the copy operation.
  699.  
  700. With either of these methods it is important to know that the routines
  701. will attempt to flesh out the destination image's color table to match
  702. the colors that are being copied from the source.  If the
  703. destination's color table is already full, then the routines will
  704. attempt to find the best match, with varying results.
  705.  
  706. =over 5
  707.  
  708. =item C<copy>
  709.  
  710. C<GD::Image::copy(sourceImage,dstX,dstY,srcX,srcY,width,height)> I<object method>
  711.  
  712. This is the simpler of the two copy operations, copying the specified
  713. region from the source image to the destination image (the one
  714. performing the method call).  (srcX,srcY) specify the upper left
  715. corner of a rectangle in the source image, and (width,height) give the
  716. width and height of the region to copy.  (dstX,dstY) control where in
  717. the destination image to stamp the copy.  You can use the same image
  718. for both the source and the destination, but the source and
  719. destination regions must not overlap or strange things will happen.
  720.  
  721. Example:
  722.  
  723.     $myImage = new GD::Image(100,100);
  724.     ... various drawing stuff ...
  725.     $srcImage = new GD::Image(50,50);
  726.     ... more drawing stuff ...
  727.     $myImage->copy($srcImage,10,10,0,0,25,25);
  728.  
  729. =item C<copyResized>
  730.  
  731. C<GD::Image::copyResized(sourceImage,dstX,dstY,srcX,srcY,destW,destH,srcW,srcH)> I<object method>
  732.  
  733. This method is similar to copy() but allows you to choose different
  734. sizes for the source and destination rectangles.  The source and
  735. destination rectangle's are specified independently by (srcW,srcH) and
  736. (destW,destH) respectively.  copyResized() will stretch or shrink the
  737. image to accomodate the size requirements.
  738.  
  739. Example:
  740.  
  741.     $myImage = new GD::Image(100,100);
  742.     ... various drawing stuff ...
  743.     $srcImage = new GD::Image(50,50);
  744.     ... more drawing stuff ...
  745.     $myImage->copyResized($srcImage,10,10,0,0,50,50,25,25);
  746.  
  747. =back
  748.  
  749. =head2 Character and String Drawing
  750.  
  751. Gd allows you to draw characters and strings, either in normal
  752. horizontal orientation or rotated 90 degrees.  These routines use a
  753. GD::Font object, described in more detail below.  There are four
  754. built-in fonts, available in global variables gdLargeFont,
  755. gdMediumBoldFont, gdSmallFont and gdTinyFont.  Currently there is no
  756. way of dynamically creating your own fonts.
  757.  
  758. =over 5
  759.  
  760. =item C<string>
  761.  
  762. C<GD::Image::string(font,x,y,string,color)> I<Object Method>
  763.  
  764. This method draws a string startin at position (x,y) in the specified
  765. font and color.  Your choices of fonts are gdSmallFont, gdMediumBoldFont,
  766. gdTinyFont and gdLargeFont.
  767.  
  768. Example:
  769.  
  770.     $myImage->string(gdSmallFont,2,10,"Peachy Keen",$peach);
  771.  
  772. =item C<stringUp>
  773.  
  774. C<GD::Image::stringUp(font,x,y,string,color)> I<Object Method>
  775.  
  776. Just like the previous call, but draws the text rotated
  777. counterclockwise 90 degrees.
  778.  
  779. =item C<char>
  780.  
  781. =item C<charUp>
  782.  
  783. C<GD::Image::char(font,x,y,char,color)> I<Object Method>
  784. C<GD::Image::charUp(font,x,y,char,color)> I<Object Method>
  785.  
  786. These methods draw single characters at position (x,y) in the
  787. specified font and color.  They're carry-overs from the C interface,
  788. where there is a distinction between characters and strings.  Perl is
  789. insensible to such subtle distinctions.
  790.  
  791. =back
  792.  
  793. =head2 Miscellaneous Image Methods
  794.  
  795. =over 5
  796.  
  797. =item C<interlaced>
  798.  
  799. C<GD::Image::interlaced( )> C<GD::Image::interlaced(1)> I<Object method>
  800.  
  801. This method sets or queries the image's interlaced setting.  Interlace
  802. produces a cool venetian blinds effect on certain viewers.  Provide a
  803. true parameter to set the interlace attribute.  Provide undef to
  804. disable it.  Call the method without parameters to find out the
  805. current setting.
  806.  
  807. =item c<getBounds>
  808.  
  809. C<GD::Image::getBounds( )> I<Object method>
  810.  
  811. This method will return a two-member list containing the width and
  812. height of the image.  You query but not not change the size of the
  813. image once it's created.
  814.  
  815.  
  816. =back
  817.  
  818. =head2 Polygon Methods
  819.  
  820. A few primitive polygon creation and manipulation methods are
  821. provided.  They aren't part of the Gd library, but I thought they
  822. might be handy to have around (they're borrowed from my qd.pl
  823. Quickdraw library).
  824.  
  825. =over 5
  826.  
  827. =item c<new>
  828.  
  829. C<GD::Polygon::new> I<class method>
  830.  
  831. Create an empty polygon with no vertices.
  832.  
  833.     $poly = new GD::Polygon;
  834.  
  835. =item C<addPt>
  836.  
  837. C<GD::Polygon::addPt(x,y)> I<object method>
  838.  
  839. Add point (x,y) to the polygon.
  840.  
  841.     $poly->addPt(0,0);
  842.     $poly->addPt(0,50);
  843.     $poly->addPt(25,25);
  844.     $myImage->fillPoly($poly,$blue);
  845.  
  846. =item C<getPt>
  847.  
  848. C<GD::Polygon::getPt(index)> I<object method>
  849.  
  850. Retrieve the point at the specified vertex.
  851.  
  852.     ($x,$y) = $poly->getPt(2);
  853.  
  854. =item C<setPt>
  855.  
  856. C<GD::Polygon::setPt(index,x,y)> I<object method>
  857.  
  858. Change the value of an already existing vertex.  It is an error to set
  859. a vertex that isn't already defined.
  860.  
  861.     $poly->setPt(2,100,100);
  862.  
  863. =item C<deletePt>
  864.  
  865. C<GD::Polygon:deletePt(index)> I<object method>
  866.  
  867. Delete the specified vertex, returning its value.
  868.  
  869.     ($x,$y) = $poly->deletePt(1); 
  870.  
  871. =item C<length>
  872.  
  873. C<GD::Polygon::length> I<object method>
  874.  
  875. Return the number of vertices in the polygon.
  876.  
  877.     $points = $poly->length;
  878.  
  879. =item C<vertices>
  880.  
  881. C<GD::Polygon::vertices> I<object method>
  882.  
  883. Return a list of all the verticies in the polygon object.  Each
  884. membver of the list is a reference to an (x,y) array.
  885.  
  886.     @vertices = $poly->vertices;
  887.     foreach $v (@vertices)
  888.        print join(",",@$v),"\n";
  889.     }
  890.  
  891. =item C<bounds>
  892.  
  893. C<GD::Polygon::bounds> I<object method>
  894.  
  895. Return the smallest rectangle that completely encloses the polygon.
  896. The return value is an array containing the (left,top,right,bottom) of
  897. the rectangle.
  898.  
  899.     ($left,$top,$right,$bottom) = $poly->bounds;
  900.  
  901. =item C<offset>
  902.  
  903. C<GD::Polygon::offset(dx,dy)> I<object method>
  904.  
  905. Offset all the vertices of the polygon by the specified horizontal
  906. (dh) and vertical (dy) amounts.  Positive numbers move the polygon
  907. down and to the right.
  908.  
  909.     $poly->offset(10,30);
  910.  
  911. =item C<map>
  912.  
  913. C<GD::Polygon::map(srcL,srcT,srcR,srcB,destL,dstT,dstR,dstB)> I<object method>
  914.  
  915. Map the polygon from a source rectangle to an equivalent position in a
  916. destination rectangle, moving it and resizing it as necessary.  See
  917. polys.pl for an example of how this works.  Both the source and
  918. destination rectangles are given in (left,top,right,bottom)
  919. coordinates.  For convenience, you can use the polygon's own bounding
  920. box as the source rectangle.
  921.  
  922.     $poly->map($poly->bounds,0,0,50,200);
  923.  
  924. =back
  925.  
  926. =head2 Font Utilities
  927.  
  928. Gd's support for fonts is minimal.  Basically you have access to
  929. gdSmallFont and gdLargeFont for drawing, and not much else.  However,
  930. for future compatibility, I've made the fonts into perl objects of
  931. type GD::Font that you can query and, perhaps someday manipulate.
  932.  
  933. =over 5
  934.  
  935. =item C<gdSmallFont>
  936.  
  937. C<GD::Font::gdSmallFont> I<constant>
  938.  
  939. This is the basic small font, "borrowed" from a well known public
  940. domain 6x12 font.
  941.  
  942. =item C<gdLargeFont>
  943.  
  944. C<GD::Font::gdLargeFont> I<constant>
  945.  
  946. This is the basic large font, "borrowed" from a well known public
  947. domain 8x16 font.
  948.  
  949. =item C<gdMediumBoldFont>
  950.  
  951. C<GD::Font::gdMediumBoldFont> I<constant>
  952.  
  953. This is a bold font intermediate in size between the small and large
  954. fonts, borrowed from a public domain 7x13 font;
  955.  
  956. =item C<gdTinyFont>
  957.  
  958. C<GD::Font::gdTinyFont> I<constant>
  959.  
  960. This is a tiny, almost unreadable font, 5x8 pixels wide.
  961.  
  962. =item C<nchars>
  963.  
  964. C<GD::Font::nchars>    I<object method>
  965.  
  966. This returns the number of characters in the font.
  967.  
  968.     print "The large font contains ",gdLargeFont->nchars," characters\n";
  969.  
  970. =item C<offset>
  971.  
  972. C<GD::Font::offset>     I<object method>
  973.  
  974. This returns the ASCII value of the first character in the font
  975.  
  976. =item C<width>
  977.  
  978. =item C<height>
  979.  
  980. C<GD::Font::width> C<GD::Font::height>    I<object methods>
  981.  
  982. These return the width and height of the font.
  983.  
  984.     ($w,$h) = (gdLargeFont->width,gdLargeFont->height);
  985.  
  986. =back
  987.  
  988. =head1 Obtaining the C-language version of gd
  989.  
  990. libgd, the C-language version of gd, can be obtained at URL
  991. http://www.boutell.com/gd/gd.html.  Directions for installing and
  992. using it can be found at that site.  Please do not contact me for help
  993. with libgd.
  994.  
  995. =head1 Copyright Information
  996.  
  997. The GD.pm interface is copyright 1995, Lincoln D. Stein.  You are free
  998. to use it for any purpose, commercial or noncommercial, provided that
  999. if you redistribute the source code this statement of copyright
  1000. remains attached. The gd library is covered separately under a 1994
  1001. copyright by Quest Protein Database Center, Cold Spring Harbor Labs
  1002. and Thomas Boutell.  For usage information see the gd documentation at
  1003. URL
  1004.  
  1005.     http://www.boutell.com/gd/gd.html
  1006.  
  1007. The latest versions of GD.pm are available at
  1008.  
  1009.   http://www.genome.wi.mit.edu/ftp/pub/software/WWW/GD.html
  1010.   ftp://ftp-genome.wi.mit.edu/pub/software/WWW/GD.pm.tar.gz
  1011.  
  1012.